<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>空置房间列表</title>
</head>
<style>
  .hotel-search body{
       
        
        background-color: #f2f2f2; 
        font-family: Arial, sans-serif;  
        margin: 0;  
        padding: 0;  }
  
    .hotel-search{  
        max-width: 800px;  
        margin: 20px auto;  
        background-color: #fff;   
        padding: 20px;  
        box-shadow: 0 0 10px rgba(0,0,0,0.1);  
    }  
   .hotel-search h1 {  
        color: #ffa500;  
        text-align: center;  
    }  
   .hotel-search table {  
        width: 100%;  
        border-collapse: collapse;  
        margin-top: 20px;  
    }  
   .hotel-search th, td {  
        padding: 8px;  
        text-align: left;  
        border-bottom: 1px solid #ddd;  
    }  
   .hotel-search th {  
        background-color: #ffa500; 
        color: #fff;  
    }  
   .hotel-search form {  
        margin-top: 20px;  
    }  
    .hotel-search input[type=text], input[type=submit] {  
        padding: 5px 10px;  
        font-size: 16px;  
    }  
   .hotel-search  input[type=submit] {  
        background-color: #ffa500; 
        color: #fff;  
        border: none;  
        cursor: pointer;  
    }  
</style>
<body>
 <div class="hotel-search">
<h1>空置房间列表</h1>
<%
    try {
        // 加载JDBC驱动
        Class.forName("org.mariadb.jdbc.Driver");

        // 数据库连接信息
        String dbURL = "jdbc:mariadb://10.220.140.102:3366/studb11";
        String username = "stua";
        String password = "zHZUA65r";

        // 建立连接
        Connection conn = DriverManager.getConnection(dbURL, username, password);

        // 查询空置房间
        String sql = "SELECT room_number, name, indate, outdate FROM 成都梦之旅文君楼庭院酒店（宽窄巷子店） WHERE status = '空置'";
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
%>
<table border="1">
    <tr>
        <th>房间号</th>
        <th>名称</th>
        <th>入住日期</th>
        <th>离店日期</th>
    </tr>
    <%
        while (rs.next()) {
    %>
    <tr>
         <td><%= rs.getString("room_number") %></td>
        <td><%= rs.getString("name") %></td>
        <td><%= rs.getString("indate") %></td>
        <td><%= rs.getString("outdate") %></td>
    </tr>
    <%
        }
    %>
</table>
<%
        
        rs.close();
        stmt.close();
        conn.close();
    } catch (Exception e) {
        e.printStackTrace(); 
    }
%>
 </div>
</body>
</html>
